package com.inibb.app.sftp;

import java.io.File;

/**
 * This class will be used as an authentication token when making a SFTPConnection
 * @author PCCW
 *
 */
public class SFTPAuthInfo
{
	private String username=null;
	private File sshKeyFile=null;
	private char[] passphrase=null;
	
	/**
	 * Create an instance of SFTPAuthInfo using username and password.
	 * @param username
	 * @param remotePassphrase
	 */
	public SFTPAuthInfo(String username, char[] remotePassphrase) {
		this.username = username;
		if (remotePassphrase!=null) this.passphrase = (char[])remotePassphrase.clone();
		else this.passphrase = null;
		this.sshKeyFile = null;
	}

	/**
	 * Create an instance of SFTPAuthInfo using username, SSH private key file, and the passphrase of the key file.
	 * @param username
	 * @param sshKeyFile
	 * @param keyFilePassphrase
	 */
	public SFTPAuthInfo(String username, File sshKeyFile, char[] keyFilePassphrase) {
		this.username = username;
		this.sshKeyFile = sshKeyFile;
		if (keyFilePassphrase!=null) this.passphrase = (char[])keyFilePassphrase.clone();
		else this.passphrase = null;
	}


	public void clear() {
		if (passphrase != null) {
			for (int i=0;i<passphrase.length;i++) {
				passphrase[i] = 0;
			}
		}
		passphrase = null;
		sshKeyFile = null;
		username = null;
	}
	
	protected void finalize()
		throws Throwable
	{
		clear();
	}

	public char[] getPassphrase() {
		return passphrase;
	}

	public void setPassphrase(char[] passphrase) {
		if (passphrase!=null) this.passphrase = (char[])passphrase.clone();
		else this.passphrase = null;
	}

	public File getSshKeyFile() {
		return sshKeyFile;
	}

	public void setSshKeyFile(File sshKeyFile) {
		this.sshKeyFile = sshKeyFile;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}
}
